{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 进阶篇：100个pandas常用的数据分析函数总结\n",
    "本期将分享比较常规的100个实用函数，这些函数大致可以分为六类，分别是统计汇总函数、数据清洗函数、数据筛选、绘图与元素级运算函数、时间序列函数和其他函数。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 一、统计汇总函数\n",
    "\n",
    "数据分析过程中，必然要做一些数据的统计汇总工作，那么对于这一块的数据运算有哪些可用的函数可以帮助到我们呢？具体看如下几张表。\n",
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/4e59b63bcf62fbeea4654620bf672686.png)\n",
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/b05f4ce8211acace3c6625ed5d1597ee.png)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9776553078928453\n",
      "0.10043364499355907\n",
      "count    1000.000000\n",
      "mean        2.195071\n",
      "std         3.040995\n",
      "min        -7.842030\n",
      "25%         0.135092\n",
      "50%         2.099099\n",
      "75%         4.229081\n",
      "max        12.215179\n",
      "dtype: float64\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "A    16.642386\n",
       "B    18.321197\n",
       "C    17.762354\n",
       "dtype: float64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = pd.Series(np.random.normal(2,3,1000))\n",
    "y = 3*x + 10 + pd.Series(np.random.normal(1,2,1000))\n",
    "\n",
    "# 计算x与y的相关系数\n",
    "print(x.corr(y))\n",
    "\n",
    "# 计算y的偏度\n",
    "print(y.skew())\n",
    "\n",
    "# 计算y的统计描述值\n",
    "print(x.describe())\n",
    "\n",
    "z = pd.Series(['A','B','C']).sample(n = 1000, replace = True)\n",
    "# 重新修改z的行索引\n",
    "z.index = range(1000)\n",
    "# 按照z分组，统计y的组内平均值\n",
    "y.groupby(by = z).aggregate(np.mean)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/a5043ff19a91538ac5033292e58c79f5.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A    334\n",
      "B    333\n",
      "C    333\n",
      "dtype: int64\n",
      "0    0.011628\n",
      "1    0.069767\n",
      "2    0.186047\n",
      "3    0.360465\n",
      "4    0.651163\n",
      "5    1.000000\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 统计z中个元素的频次\n",
    "print(z.value_counts())\n",
    "\n",
    "a = pd.Series([1,5,10,15,25,30])\n",
    "# 计算a中各元素的累计百分比\n",
    "print(a.cumsum() / a.cumsum()[a.size - 1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 二、数据清洗函数\n",
    "\n",
    "同样，数据清洗工作也是必不可少的工作，在如下表格中罗列了常有的数据清洗的函数。\n",
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/a7be2557201dc99ecd004934198f01dc.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "0    10.0\n",
      "1    13.0\n",
      "2    21.0\n",
      "3    17.0\n",
      "4    28.0\n",
      "5    19.0\n",
      "6    33.0\n",
      "7    21.0\n",
      "8    27.0\n",
      "dtype: float64\n",
      "0    10.0\n",
      "1    13.0\n",
      "2    13.0\n",
      "3    17.0\n",
      "4    28.0\n",
      "5    19.0\n",
      "6    33.0\n",
      "7    33.0\n",
      "8    27.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "x = pd.Series([10,13,np.nan,17,28,19,33,np.nan,27])\n",
    "#检验序列中是否存在缺失值\n",
    "print(x.hasnans)\n",
    " \n",
    "# 将缺失值填充为平均值\n",
    "print(x.fillna(value = x.mean()))\n",
    " \n",
    "# 前向填充缺失值\n",
    "print(x.ffill())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/e78497a17379bd08e383561ca040b854.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    12500\n",
      "1     8000\n",
      "2     8500\n",
      "3    15000\n",
      "4     9000\n",
      "dtype: int32\n",
      "(array([0, 1, 1, 1, 0, 1], dtype=int64), Index(['男', '女'], dtype='object'))\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0    158.32\n",
       "1    104.73\n",
       "2     68.38\n",
       "dtype: float64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "income = pd.Series(['12500元','8000元','8500元','15000元','9000元'])\n",
    "# 将收入转换为整型\n",
    "print(income.str[:-1].astype(int))\n",
    " \n",
    "gender = pd.Series(['男','女','女','女','男','女'])\n",
    "# 性别因子化处理\n",
    "print(gender.factorize())\n",
    " \n",
    "house = pd.Series(['大宁金茂府 | 3室2厅 | 158.32平米 | 南 | 精装',\n",
    "                   '昌里花园 | 2室2厅 | 104.73平米 | 南 | 精装',\n",
    "                   '纺大小区 | 3室1厅 | 68.38平米 | 南 | 简装'])\n",
    "# 取出二手房的面积，并转换为浮点型\n",
    "house.str.split('|').str[2].str.strip().str[:-2].astype(float)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三、数据筛选\n",
    "\n",
    "数据分析中如需对变量中的数值做子集筛选时，可以巧妙的使用下表中的几个函数，其中部分函数既可以使用在序列身上，也基本可以使用在数据框对象中。\n",
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/f9b60d2971fa2229d7b416d12750099d.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4    18\n",
      "5    19\n",
      "7    17\n",
      "8    19\n",
      "dtype: int32\n",
      "0    13\n",
      "1    16\n",
      "2    15\n",
      "3    14\n",
      "9    16\n",
      "dtype: int32\n",
      "5    19\n",
      "8    19\n",
      "4    18\n",
      "dtype: int32\n",
      "0    24\n",
      "1    27\n",
      "2    21\n",
      "dtype: int32\n"
     ]
    }
   ],
   "source": [
    "np.random.seed(1234)\n",
    "x = pd.Series(np.random.randint(10,20,10))\n",
    " \n",
    "# 筛选出16以上的元素\n",
    "print(x.loc[x > 16])\n",
    "\n",
    "# print(x.compress(x > 16))\n",
    " \n",
    "# 筛选出13~16之间的元素\n",
    "print(x[x.between(13,16)])\n",
    " \n",
    "# 取出最大的三个元素\n",
    "print(x.nlargest(3))\n",
    " \n",
    "y = pd.Series(['ID:1 name:张三 age:24 income:13500',\n",
    "               'ID:2 name:李四 age:27 income:25000',\n",
    "               'ID:3 name:王二 age:21 income:8000'])\n",
    "# 取出年龄，并转换为整数\n",
    "print(y.str.findall('age:(\\d+)').str[0].astype(int))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 四、绘图与元素级函数\n",
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/a7e3fdcb346c8565d909082a34bd70b5.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9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PTJv2Ei30zx9X12Nelt12QqsrW6vBW7uMWakp8+IiAuBDwNvy8z/6TOmznM97Fzd7828vc/6luJUI28Gvp+Ze3vNbHJbHaIHWrdfNfIu7TAudD7l8QM67y5/tJr2XuC91e2g8x+C/BDYDkw0nOfP6fwJ9TDwYHW5aF6m9wE76LwLfg/wZw1nemW1roeq9S75durK9vt0yvqErmkj3VZ0frHsA/6PzqumK4E/AO4EHquuT6rGvgK47VD7X4OZdtM5Fntgv/qn+Zn6PdcN5/qXap95mE4JLV/qbVVN/9KB/ahr7Ei21SF6YEn3q14Xv6EqSQVq62EZSdIALHdJKpDlLkkFstwlqUCWuyQVyHKXpAJZ7pJUIMtdkgr0/yZ1o7aiLFq5AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAATFklEQVR4nO3df4xd5X3n8fdnHTt0EwRtmRAwP5xdIWp3tlB25CaCjeLNGjCLCq2iLkOU0mDF5de0XXVXhR2pP1ZCy2qVbhs7sestLLAKk6RtoGhtB1vIUmqRtIxZIAY3Gy8LwjWCSVlMmgRsk+/+MddkMrnje+fescdzeL+k0ZzznOec8x3J+vjoOc+9T6oKSVJz/aP5LkCSdHwZ9JLUcAa9JDWcQS9JDWfQS1LDvWu+C2jnjDPOqGXLls13GZK0YOzevfvbVTXQ7thJGfTLli1jfHx8vsuQpAUjyQszHXPoRpIazqCXpIYz6CWp4Qx6SWo4g16SGs6gl7owNjbG4OAgixYtYnBwkLGxsfkuSeraSTm9UjqZjI2NMTo6yt13381ll13Grl27WLt2LQDDw8PzXJ3U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bqrqSJLbgEeARcA9VfVMkptaxzcBW4GrgH3A94BP9l+yJGk2+vpkbFVtZTLMp7ZtmrJdwK393EOS1B8/GStJDXdSfqlZkgnALxLRyegM4NvzXYTUxvlVNdDuwEkZ9NLJKsn4TN8QKJ2sHLqRpIYz6CWp4Qx6aXY2z3cB0mw5Ri9JDecTvSQ1nEEvSQ1n0OsdLUkl+fSU/X+X5PfnsSRpzhn0eqd7E/jlJGfMdyHS8WLQ653uCJMzaf7t9ANJzk/yaGu940eTnNdqv7e1FvJjSZ5L8rEp5/z7JI+3zvmDE/dnSDMz6KXJtY8/nuS0ae0bmFwK8+eAzwOfmXLsLOAy4GrgLoAklzO5PvJK4GLgnyf58PEtXerMoNc7XlW9DtwP/Ma0Qx8CHmht/w8mg/2oh6rqB1X1LHBmq+3y1s//Ap4AfobJ4JfmVV9fUyw1yB8xGc7//Rh9pn7o5M0p25ny+z9V1Z/MbWlSf3yil4CqehX4ErB2SvNjTK6cBvBxYFeHyzwC3JjkvQBJliZ531zXKs2WQS/90KeZ/Brio34D+GSSp4FPAL95rJOrajuTQz1fS/IN4M+BU49TrVLX/AoESWo4n+glqeEMeklqOINekhrOoJekhjPoJanhDHpJajiDXpIa7v8DOqI7bdYxVRYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "0     1280.0000\n",
       "1    67000.0000\n",
       "2     2488.0000\n",
       "3     1892.0000\n",
       "4        0.9877\n",
       "5     9877.0000\n",
       "6    12000.0000\n",
       "dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.seed(123)\n",
    "import matplotlib.pyplot as plt\n",
    "x = pd.Series(np.random.normal(10,3,1000))\n",
    "# 绘制x直方图\n",
    "x.hist()\n",
    "# 显示图形\n",
    "plt.show()\n",
    " \n",
    "# 绘制x的箱线图\n",
    "x.plot(kind='box')\n",
    "plt.show()\n",
    " \n",
    "installs = pd.Series(['1280万','6.7亿','2488万','1892万','9877','9877万','1.2亿'])\n",
    "# 将安装量统一更改为“万”的单位\n",
    "def transform(x):\n",
    "    if x.find('亿') != -1:\n",
    "        res = float(x[:-1])*10000\n",
    "    elif x.find('万') != -1:\n",
    "        res = float(x[:-1])\n",
    "    else:\n",
    "        res = float(x)/10000\n",
    "    return res\n",
    "installs.apply(transform)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 五、时间序列函数\n",
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/e924378d96dbc7c5c6d92dca2996e965.png)\n",
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/e50c552a75c68ea5dc80c2bcb781a2ce.png)\n",
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/150a67225fcc3238ab723b742685f619.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 六、其他函数\n",
    "![](https://zhangyafei-1258643511.cos.ap-nanjing.myqcloud.com/image/e6aa6f62ab26f4d8982d9aafd88ff729.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    12\n",
      "1    16\n",
      "2     9\n",
      "3    12\n",
      "4    13\n",
      "5    15\n",
      "dtype: int32\n",
      "0    NaN\n",
      "1    4.0\n",
      "2   -7.0\n",
      "3    3.0\n",
      "4    1.0\n",
      "5    2.0\n",
      "dtype: float64\n",
      "1    16\n",
      "5    15\n",
      "4    13\n",
      "0    12\n",
      "3    12\n",
      "2     9\n",
      "dtype: int32\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[8, 12, 9, 10, 13, 15, 14, 11]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.seed(112)\n",
    "x = pd.Series(np.random.randint(8,18,6))\n",
    "print(x)\n",
    "# 对x中的元素做一阶差分\n",
    "print(x.diff())\n",
    " \n",
    "# 对x中的元素做降序处理\n",
    "print(x.sort_values(ascending = False))\n",
    " \n",
    "y = pd.Series(np.random.randint(8,16,100))\n",
    "# 将y中的元素做排重处理，并转换为列表对象\n",
    "y.unique().tolist()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
